<template>
	<w-layout showNavbar navTitle="抽卡记录" :navTitleColor="publicStyles['--color-t1']" background="url('/static/image/bk.png') no-repeat"
		navBackgroundColor="transparent" :scrollTop="page.scrollTop" :navScrollColor="publicStyles['--color-bk']">
		<template #default>
			<view class="container">
				<view class="">
					<up-tabs
						@change="tabChange"
						:list="tabs.list" 
						:current="tabs.current"
						lineWidth="14"
						lineHeight="14"
						:lineColor="`url('/static/icon/public/top-fill.png') 100% 100%`"
						:activeStyle="{
							color: publicStyles['--color'],
							fontWeight: 'bold',
							transform: 'scale(1.2)'
						}"
						:scrollable="true"
						itemStyle="height: 60px;"
						:inactiveStyle="{
							'font-size': '32rpx',
						}"
					>
					</up-tabs>
				</view>
				<view class="op-50 mt-30">
					由于数据反馈会有延迟，榜单呈现时间会有误差
				</view>
				
				<view class="mt-40 u-border-bottom pb-30 fr-ac" style="border-color: var(--gray-line) !important;" v-for="(item,index) in state.list" :key="index">
					<view class="fr-ac w-52">
						<view class="color bold mr-30">
							{{index+1}}
						</view>
						<view class="" style="position: relative;">
							<image style="width: 80rpx;height: 80rpx;border-radius: 50%;" :src="item.headimg" mode=""></image>
							<image v-if="item.vip_imgurl" style="width: 80rpx;height: 80rpx;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);" :src="item.vip_imgurl" mode="widthFix"></image>
						</view>
						<view class="flex-1 mx-20">
							<view class="ellipsis-1 op-90">
								{{item.nickname}}
							</view>
							<view class="ellipsis-1 op-50 mt-10 fs-24">
								{{item.addtime}}
							</view>
						</view>
					</view>
					
					<view class="flex-1 fr-ac">
						<image style="width: 80rpx;height: 80rpx;" :src="item.goodslist_imgurl" mode=""></image>
						<view class="ml-15 flex-1">
							<view class="ellipsis-1 op-90">
								{{item.goodslist_title}}
							</view>
							<!-- <view class="color mt-10">
								¥ 199.00
							</view> -->
						</view>
						<view class="ml-auto">
							<cut-corner :arrow="3" clipSize="8rpx">
								<view class="color fr-ac-jc fs-26" style="width: 54rpx;height: 50rpx;background-color: #153E4C;">
									x{{item.prize_num}}
								</view>
							</cut-corner>
						</view>
					</view>
				</view>
				<no-more :show="state.list.length == 0"></no-more>
				
			</view>
		</template>
	</w-layout>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		computed,
		nextTick
	} from 'vue'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad, onPageScroll,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		useAppStore
	} from '@/store/app'
	import {
		useColorStore
	} from '@/store/color'
	import {
		cardextractor_shang_log
	} from '@/utils/request/api';
	import {
		useUserStore
	} from '@/store/user'
	const userStore = useUserStore()
	const appStore = useAppStore()
	const colorStore = useColorStore()
	const {
		publicStyles
	} = storeToRefs(colorStore)
	onLoad(async(options) => {
		if(options.id){
			state.goods_id = options.id
			get_cardextractor_shang_log()
		}
	})
	onMounted(() => {
		appStore.loadingHandler(false)
	})
	onPageScroll((e)=>{
		page.scrollTop = e.scrollTop
	})
	onReachBottom(()=>{
		if(state.last_limit == state.limit){
			state.page++
			get_cardextractor_shang_log()
		}
	})
	const page = reactive({
		scrollTop:0
	})
	
	const tabs = reactive({
		current:0,
		list:[]
	})
	function tabChange(e){
		tabs.current = e.index
		console.log(tabs.current)
		initData()
		get_cardextractor_shang_log()
	}
	
	const state = reactive({
		goods_id: '',
		
		list:[],
		page:1,
		limit:20,
		last_limit:20,
		
		keyword:'',
	})
	function initData(){
		state.list = []
		state.page = 1
		state.last_limit = 20
	}
	async function get_cardextractor_shang_log(){
		const res = await cardextractor_shang_log({
			page: state.page,
			goods_id: state.goods_id,
			shang_id: tabs.list.length? tabs.list[tabs.current].id : 0
		})
		state.last_limit = res.data.length
		state.list = state.list.concat(res.data)
		
		tabs.list = res.category.map(e=>{
			return{
				...e,
				name: e.title
			}
		})
	}
	
</script>

<style lang="scss">
	.shadow {
		box-shadow: 2rpx 2rpx 12rpx var(--shadow);
	}
	.color{
		color: var(--color);
	}

	.container {
		width: 100%;
		min-height: 100%;
		position: relative;
		overflow: hidden;
		box-sizing: border-box;
		padding: 0 30rpx;
		
	}
</style>